package cn.yangphere.web.action.product;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.stereotype.Controller;

import cn.yangphere.bean.PageView;
import cn.yangphere.bean.QueryResult;
import cn.yangphere.bean.product.Brand;
import cn.yangphere.service.product.BrandService;
import cn.yangphere.web.formbean.product.BrandForm;

@Controller("/control/brand/list")
public class BrandAction extends Action {

	@Resource(name="brandServiceBean")
	private BrandService brandService;
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		BrandForm formBean = (BrandForm) form;
		StringBuffer jpql = new StringBuffer("o.visible=?1");
		List<Object> params = new ArrayList<Object>();
		params.add(true);
		
		PageView<Brand> pageView = new PageView<Brand>(12, formBean.getPage());
		QueryResult<Brand> qr = brandService.getScrollData(Brand.class, 
				pageView.getFirstIndex(), pageView.getMaxResult(),
				jpql.toString(), params.toArray());
		pageView.setQueryResult(qr);
		
		request.setAttribute("pageView", pageView);	
		
		return mapping.findForward("list");
	}

}
